//3.观察者模式之promise
class Promise{
    constructor(fn){
        this.successes =[];
        let resolve = (res)=>{
            this.successes.forEach(success=>success(res))
        }
        fn(resolve);
    }
    then(success){
        this.successes.push(success);
    }
}
let p = new Promise(function (resolve) { 
    setTimeout(function () { 
        resolve('ok')
     },3000)
 });
 p.then(data=>console.log(data));